package com.glsc.ngateway.common.base.converter.platform;

import cn.hutool.json.JSONUtil;
import com.alibaba.excel.util.CollectionUtils;
import com.glsc.ngateway.common.base.domain.mysql.gateway.platform.it.networkassets.HostInformationMaintenance;
import com.glsc.ngateway.common.base.domainmapper.HostInformationMaintenanceMapper;
import com.glsc.ngateway.common.api.platform.dto.it.networkassets.HostInformationMaintenanceDto;
import org.apache.commons.lang.StringUtils;

import java.util.List;
import java.util.stream.Collectors;

public class HostInformationMaintenanceConverter {
    public static HostInformationMaintenanceDto do2Dto(HostInformationMaintenance domain){
        HostInformationMaintenanceDto hostDto = HostInformationMaintenanceMapper.INSTANCE.domain2dto(domain);
        hostDto.setTaskList(StringUtils.isBlank(hostDto.getTask()) ? java.util.Collections.EMPTY_LIST : JSONUtil.parseArray(hostDto.getTask()).toList(String.class));
        hostDto.setBindSerialNumList(StringUtils.isBlank(hostDto.getBindSerialNum()) ? java.util.Collections.EMPTY_LIST : JSONUtil.parseArray(hostDto.getBindSerialNum()).toList(String.class));
        hostDto.setDeployedModeList(StringUtils.isBlank(hostDto.getDeployedMode()) ? java.util.Collections.EMPTY_LIST : JSONUtil.parseArray(hostDto.getDeployedMode()).toList(String.class));
        return hostDto;
    }

    public static List<HostInformationMaintenanceDto> do2Dto(List<HostInformationMaintenance> doList) {
        return CollectionUtils.isEmpty(doList) ? java.util.Collections.emptyList() : doList.stream().map(HostInformationMaintenanceConverter::do2Dto).collect(Collectors.toList());
    }

    public static HostInformationMaintenance dto2Do(HostInformationMaintenanceDto dto){
        HostInformationMaintenance hostDo = HostInformationMaintenanceMapper.INSTANCE.dto2domain(dto);
        hostDo.setTask(CollectionUtils.isEmpty(dto.getTaskList()) ? null : JSONUtil.toJsonStr(dto.getTaskList()));
        hostDo.setBindSerialNum(CollectionUtils.isEmpty(dto.getBindSerialNumList()) ? null : JSONUtil.toJsonStr(dto.getBindSerialNumList()));
        hostDo.setDeployedMode(CollectionUtils.isEmpty(dto.getDeployedModeList()) ? null : JSONUtil.toJsonStr(dto.getDeployedModeList()));
        return hostDo;
    }
    public static List<HostInformationMaintenance> dto2Do(List<HostInformationMaintenanceDto> dtoList) {
        return CollectionUtils.isEmpty(dtoList) ? java.util.Collections.emptyList() : dtoList.stream().map(HostInformationMaintenanceConverter::dto2Do).collect(Collectors.toList());
    }
}
